package cn.gjxblog.mq.custom;

import cn.gjxblog.mq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.QueueingConsumer;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/7/4 11:48
 */
public class Consumer {
    public static void main(String[] args) throws Exception {
        //1 获取连接
        Connection connection = ConnectionUtils.getConnection();

        //2通过connection创建channel
        Channel channel = connection.createChannel();

        //3 声明交换机和队列然后进行绑定设置。
        String exchangeName = "test_custom_exchange";
        String routingKey = "custom.#";
        String queueName = "test_custom_queue";
        channel.exchangeDeclare(exchangeName,"topic",true);
        channel.queueDeclare(queueName,true,false,false,null);
        channel.queueBind(queueName,exchangeName,routingKey);

        //4 设置chanel
        channel.basicConsume(queueName,true,new CustomConsumer(channel));



    }
}
